{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "    ## 7.1.微小图像数据集"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Files already downloaded and verified\n",
      "Files already downloaded and verified\n"
     ]
    }
   ],
   "source": [
    "from torchvision import datasets\n",
    "data_path = '../data2/p1ch7/'\n",
    "cifar10 = datasets.CIFAR10(data_path,train=True,download=True)\n",
    "cifar10_val = datasets.CIFAR10(data_path,train=False,download=True)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:10:54.681852300Z",
     "start_time": "2023-10-15T09:10:23.308193800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "(torchvision.datasets.cifar.CIFAR10,\n torchvision.datasets.vision.VisionDataset,\n torch.utils.data.dataset.Dataset,\n typing.Generic,\n object)"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(cifar10).__mro__"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:19:49.230598400Z",
     "start_time": "2023-10-15T09:19:49.189605400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "50000"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(cifar10)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:19:52.377620500Z",
     "start_time": "2023-10-15T09:19:52.355614900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "(<PIL.Image.Image image mode=RGB size=32x32>, 2, 'bird')"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class_names = ['airplane','automobile','bird','cat','deer',\n",
    "               'dog','frog','horse','ship','truck']\n",
    "img,label = cifar10[6]\n",
    "img,label,class_names[label] # 返回图像和标签"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:20:55.065545100Z",
     "start_time": "2023-10-15T09:20:55.046555200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAwBklEQVR4nO3dbWxcdXr38d/MeGY8tsdPSfyUOMELCQsEslpCISkLgRbfeFUEm63ELtIqqC1algcpyq5oAy+wKjVBVESslJK22xUFFQovChQJFkgFSbpKs0q4QWQDC2FjiJPYcezYHns8nsdzv+COuyYhXP9g87ed70caKZ65cvl/5pyZy8ee+U0oCIJAAAB4EPa9AADA+YshBADwhiEEAPCGIQQA8IYhBADwhiEEAPCGIQQA8IYhBADwpsz3Aj6vVCrp2LFjSiaTCoVCvpcDAHAUBIFGRkbU0tKicPjs5zozbggdO3ZMra2tvpcBAPiKuru7tWjRorPWTNsQeuKJJ/T3f//36unp0WWXXabHH39c3/nOd770/yWTSUnSz3/1XSUqo6bv9ZtdfeZ1VcWXmWslqaIiaa6NhtzuzsoK2/ZJ0rzqJqfetRUL7bXV1U69eweOONV/0r/fXJtsSTv1rm+210fjGafemfSwuba83L4vJSkSqnWqLxUL5tpicdSpd211i7k2Hks49Y7IvpbUSM6p98m+iLk2m65x6j2WrXSqD2RPPxsa7HXqncnY75eRUfsxK0mBiubaoUH7vsxni3pxy/+deD4/m2kZQs8//7zWr1+vJ554Qn/8x3+sf/qnf1JHR4fef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LigvNtWO5A069w2VHzLW5olvcUGWVPc6oZH+6cqrlTAgA4I3TENq8ebOuuuoqJZNJNTQ06LbbbtOHH344qSYIAnV2dqqlpUWJREJr1qzRgQNukx8AcH5wGkI7d+7Uvffeqz179mj79u0qFApqb29XOv2/KbyPPvqotmzZoq1bt2rv3r1qamrSTTfdpJERt19XAADmPqdf8L722muTvn7yySfV0NCgt99+W9ddd52CINDjjz+uhx56SGvXrpUkPfXUU2psbNSzzz6rH//4x1O3cgDArPeV/iY0PPzZZ1HU19dLkrq6utTb26v29vaJmng8ruuvv167d+8+Y49sNqtUKjXpAgA4P5zzEAqCQBs2bNC1116r5cuXS5J6ez97BUpjY+Ok2sbGxonbPm/z5s2qqamZuLS2tp7rkgAAs8w5D6H77rtP7733nv793//9tNtCockvsw2C4LTrTtm4caOGh4cnLt3dbp+uCACYvc7pfUL333+/Xn75Ze3atUuLFv3v68ybmpokfXZG1NzcPHF9X1/faWdHp8TjccXjjm8QAADMCU5nQkEQ6L777tMLL7ygN998U21tk9/k2NbWpqamJm3fvn3iulwup507d2r16tVTs2IAwJzhdCZ077336tlnn9V//ud/KplMTvydp6amRolEQqFQSOvXr9emTZu0dOlSLV26VJs2bVJFRYXuuOOOadkAAMDs5TSEtm3bJklas2bNpOuffPJJ3XnnnZKkBx54QJlMRvfcc48GBwd19dVX64033lAymZySBQMA5g6nIWTJagqFQurs7FRnZ+e5rkmSNJ4bVyRnW14uU3Tom3FaRzGw1xcKJ516F2TPsRsbdnuzbzhuz2Arq3T70+BQv9vL6Pt7HLKvAnuOmSQVimPm2qra5i8v+sPe4/bsuFLOvg5JGsuccKofL/aZa0OxqFPvsqg9g23+Irf78KJl9lzC3gG3bL+YPZZOobBb71za7bHcVHe5vTjc4tQ7qLI/3j783aBT7+YFZ/5b/ZlUxivMtZmI/bmN7DgAgDcMIQCANwwhAIA3DCEAgDcMIQCANwwhAIA3DCEAgDcMIQCANwwhAIA3DCEAgDfn9FEOX4diKaRiyRY9U7Knjqg85pZ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DVq2bJnuuusu9fX1+V7SVzI8PCxJqq+vlzR39+fnt/OUubQ/i8WinnvuOaXTaa1atepr35czfgj19/erWCyqsbFx0vWNjY3q7e31tKqpd/XVV+vpp5/W66+/rl/84hfq7e3V6tWrNTAw4Htp0+LUvpvr+1WSOjo69Mwzz+jNN9/UY489pr179+rGG29UNmv/HKyZJAgCbdiwQddee62WL18uaW7uzzNtpzR39uf+/ftVVVWleDyuu+++Wy+++KIuvfTSr31fzrgU7S/yhx/rIH12gHz+utmso6Nj4t+XX365Vq1apQsvvFBPPfWUNmzY4HFl02uu71dJuv322yf+vXz5cq1cuVJLlizRK6+8orVr13pc2bm577779N577+nXv/71abfNpf35Rds5V/bnxRdfrHfffVdDQ0P6j//4D61bt047d+6cuP3r2pcz/kxo/vz5ikQip03gvr6+0yb1XFJZWanLL79cBw8e9L2UaXHqlX/n236VpObmZi1ZsmRW7tv7779fL7/8st56661JH7ky1/bnF23nmczW/RmLxXTRRRdp5cqV2rx5s1asWKGf//znX/u+nPFDKBaL6corr9T27dsnXb99+3atXr3a06qmXzab1QcffKDm5mbfS5kWbW1tampqmrRfc7mcdu7cOaf3qyQNDAyou7t7Vu3bIAh033336YUXXtCbb76ptra2SbfPlf35Zdt5JrNxf55JEATKZrNf/76c8pc6TIPnnnsuiEajwS9/+cvg/fffD9avXx9UVlYGn3zyie+lTZmf/vSnwY4dO4JDhw4Fe/bsCf7sz/4sSCaTs3obR0ZGgnfeeSd45513AknBli1bgnfeeSf49NNPgyAIgkceeSSoqakJXnjhhWD//v3BD3/4w6C5uTlIpVKeV+7mbNs5MjIS/PSnPw12794ddHV1BW+99VawatWqYOHChbNqO3/yk58ENTU1wY4dO4Kenp6Jy9jY2ETNXNifX7adc2V/bty4Mdi1a1fQ1dUVvPfee8GDDz4YhMPh4I033giC4Ovdl7NiCAVBEPzDP/xDsGTJkiAWiwXf/va3J71kci64/fbbg+bm5iAajQYtLS3B2rVrgwMHDvhe1lfy1ltvBZJOu6xbty4Igs9e1vvwww8HTU1NQTweD6677rpg//79fhd9Ds62nWNjY0F7e3uwYMGCIBqNBosXLw7WrVsXHD582PeynZxp+yQFTz755ETNXNifX7adc2V//sVf/MXE8+mCBQuCP/mTP5kYQEHw9e5LPsoBAODNjP+bEABg7mIIAQC8YQgBALxhCAEAvGEIAQC8YQgBALxhCAEAvGEIAQC8YQgBALxhCAEAvGEIAQC8YQgBALz5f0k/tB/p1rdZAAAAAElFTkSuQmCC"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.imshow(img)\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:20:57.157679300Z",
     "start_time": "2023-10-15T09:20:56.972652Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 7.1.3. Dataset变换\n",
    "<P>将图片转化为张量</P>"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "['AugMix',\n 'AutoAugment',\n 'AutoAugmentPolicy',\n 'CenterCrop',\n 'ColorJitter',\n 'Compose',\n 'ConvertImageDtype',\n 'ElasticTransform',\n 'FiveCrop',\n 'GaussianBlur',\n 'Grayscale',\n 'InterpolationMode',\n 'Lambda',\n 'LinearTransformation',\n 'Normalize',\n 'PILToTensor',\n 'Pad',\n 'RandAugment',\n 'RandomAdjustSharpness',\n 'RandomAffine',\n 'RandomApply',\n 'RandomAutocontrast',\n 'RandomChoice',\n 'RandomCrop',\n 'RandomEqualize',\n 'RandomErasing',\n 'RandomGrayscale',\n 'RandomHorizontalFlip',\n 'RandomInvert',\n 'RandomOrder',\n 'RandomPerspective',\n 'RandomPosterize',\n 'RandomResizedCrop',\n 'RandomRotation',\n 'RandomSolarize',\n 'RandomVerticalFlip',\n 'Resize',\n 'TenCrop',\n 'ToPILImage',\n 'ToTensor',\n 'TrivialAugmentWide',\n '__builtins__',\n '__cached__',\n '__doc__',\n '__file__',\n '__loader__',\n '__name__',\n '__package__',\n '__path__',\n '__spec__',\n '_functional_pil',\n '_functional_tensor',\n '_presets',\n 'autoaugment',\n 'functional',\n 'transforms']"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from torchvision import transforms\n",
    "dir(transforms)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:21:08.770501800Z",
     "start_time": "2023-10-15T09:21:08.740510600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "torch.Size([3, 32, 32])"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from torchvision import transforms\n",
    "to_tensor = transforms.ToTensor() # 将图片转化为张量\n",
    "img_t = to_tensor(img)\n",
    "img_t.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:21:40.454328600Z",
     "start_time": "2023-10-15T09:21:39.359833100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "data": {
      "text/plain": "torch.Tensor"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将变换作为参数直接传递给dataset.CIFAR10\n",
    "tensor_cifar10 = datasets.CIFAR10(data_path,train=True,download=False,transform=transforms.ToTensor())\n",
    "img_t,_=tensor_cifar10[99]\n",
    "type(img_t)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:22:28.166928900Z",
     "start_time": "2023-10-15T09:22:27.185928900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "(torch.Size([3, 32, 32]), torch.float32)"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img_t.shape,img_t.dtype"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:22:34.223610600Z",
     "start_time": "2023-10-15T09:22:34.206614800Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "(tensor(0.), tensor(1.))"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img_t.min(),img_t.max() # toTensor会将变量的取值范围压缩到（0-1）之间"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:22:37.776406500Z",
     "start_time": "2023-10-15T09:22:37.666400900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAvEUlEQVR4nO3df5DUdX7n8VdPd0/Pr56BAeaXjOy4gL9QLiuuwrqKJM45uXi6bCruereFl8Rb1x9VFLtlgtaVXKoClikpt45Iks0W0YtG6y5qrNJVySGQLZYcGIksuh6uwzIKwwDC9Pzo6e7p/t4frnM3gvp+w4yfmeH5qOoq6H7z5vP9frv73d/p6VfHoiiKBABAAGWhFwAAOHcxhAAAwTCEAADBMIQAAMEwhAAAwTCEAADBMIQAAMEwhAAAwSRCL+CTSqWSDh06pHQ6rVgsFno5AACnKIrU19enlpYWlZV99rnOhBtChw4dUmtra+hlAADOUldXl2bPnv2ZNeM2hB577DH92Z/9mQ4fPqxLL71Ujz76qL7+9a9/7r9Lp9OSpK9ePV+JRNz0fw30nTCvazifM9dKUjxp/4llZaXvzC0qOXZ/me9QFRzbadzNI0r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2308kKTnsy3fzKDpyzyR5tlKRq9rX3Jkc51y3l3c1dkXvLozZ71vlzi397+X2p+lHaitcvS+aP9dc25qy75TCcFEHtr1hquVMCAAQjGsIrVu3TldeeaXS6bQaGhp0yy236J133hlVc/vttysWi426XH311WO6aADA1OAaQtu2bdPdd9+tnTt3avPmzRoeHlZ7e7sGBgZG1d144406fPjwyOWll14a00UDAKYG13tCL7/88qi/b9q0SQ0NDXr99dd17bXXjlyfSqXU1NQ0NisEAExZZ/WeUG/vR2/y19fXj7p+69atamho0Pz583XHHXeop6fnU3vkcjllMplRFwDAueGMh1AURVq1apWuueYaLViwYOT6jo4OPfnkk9qyZYseeeQR7dq1S8uWLVMulzttn3Xr1qmurm7k0traeqZLAgBMMmf8K9r33HOP3nzzTf30pz8ddf2tt9468ucFCxZo0aJFmjNnjl588UUtX778lD6rV6/WqlWrRv6eyWQYRABwjjijIXTvvffqhRde0Pbt2zV79uzPrG1ubtacOXO0f//+096eSqWUSqXOZBkAgEnONYSiKNK9996r5557Tlu3blVbW9vn/pvjx4+rq6tLzc3NZ7xIAMDU5HpP6O6779bf/u3f6qmnnlI6nVZ3d7e6u7uVzWYlSf39/frBD36gn/3sZzpw4IC2bt2qm266STNnztQ3vvGNcdkAAMDk5ToT2rhxoyRp6dKlo67ftGmTbr/9dsXjce3du1dPPPGETp48qebmZl1//fV65plnlE6nx2zRAICpwf3juM9SWVmpV1555awW9LFUqkIVFbb8s8TP3jL3nXbypGsdOUfOkyvHTFI+Zq//r1W+9832tDaYa8+/+CJX71lNX3LVH/s/+8y1c3+6y9V7Vc6e7xZ3Hp+S4wcF3twzx6GXJBVj43c/LHMt3relnpX41iFFjp3oPj7OfZgo2XPseh3HUpKeSdqfpi9obnT1/r1/97vm2upq+3NQNjukl8mOAwBMdAwhAEAwDCEAQDAMIQBAMAwhAEAwDCEAQDAMIQBAMAwhAEAwDCEAQDAMIQBAMGf8fULjrZAdVr5ki8647Jf2b2NNpMpd64hlT/9lfKdXdPV+ubzS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9sBwBTQ1dWl2bNnf2bNhBtCpVJJhw4dUjqdHvVleJlMRq2trerq6lJtbW3AFY4vtnPqOBe2UWI7p5qx2M4oitTX16eWlhaVlX32uz4T7sdxZWVlnzk5a2trp/Qd4GNs59RxLmyjxHZONWe7nXV1daY6fjEBABAMQwgAEMykGUKpVEoPPvigUqlU6KWMK7Zz6jgXtlFiO6eaL3o7J9wvJgAAzh2T5kwIADD1MIQAAMEwhAAAwTCEAADBTJoh9Nhjj6mtrU0VFRW64oor9E//9E+hlzSm1qxZo1gsNurS1NQUellnZfv27brpppvU0tKiWCym559/ftTtURRpzZo1amlpUWVlpZYuXap9+/aFWexZ+LztvP322085tldffXWYxZ6hdevW6corr1Q6nVZDQ4NuueUWvfPOO6NqpsLxtGznVDieGzdu1OWXXz7ygdTFixfrJz/5ycjtX+SxnBRD6JlnntHKlSv1wAMP6I033tDXv/51dXR06ODBg6GXNqYuvfRSHT58eOSyd+/e0Es6KwMDA1q4cKE2bNhw2tsffvhhrV+/Xhs2bNCuXbvU1NSkG264QX19fV/wSs/O522nJN14442jju1LL730Ba7w7G3btk133323du7cqc2bN2t4eFjt7e0aGBgYqZkKx9OyndLkP56zZ8/WQw89pN27d2v37t1atmyZbr755pFB84Uey2gS+OpXvxrdeeedo6676KKLoj/+4z8OtKKx9+CDD0YLFy4MvYxxIyl67rnnRv5eKpWipqam6KGHHhq5bmhoKKqrq4v+4i/+IsAKx8YntzOKomjFihXRzTffHGQ946WnpyeSFG3bti2Koql7PD+5nVE0NY9nFEXR9OnTo7/+67/+wo/lhD8Tyufzev3119Xe3j7q+vb2du3YsSPQqsbH/v371dLSora2Nn3rW9/Se++9F3pJ46azs1Pd3d2jjmsqldJ111035Y6rJG3dulUNDQ2aP3++7rjjDvX09IRe0lnp7e2VJNXX10uausfzk9v5sal0PIvFop5++mkNDAxo8eLFX/ixnPBD6NixYyoWi2psbBx1fWNjo7q7uwOtauxdddVVeuKJJ/TKK6/oRz/6kbq7u7VkyRIdP3489NLGxcfHbqofV0nq6OjQk08+qS1btuiRRx7Rrl27tGzZMuUc3+UykURRpFWrVumaa67RggULJE3N43m67ZSmzvHcu3evampqlEqldOedd+q5557TJZdc8oUfywmXov1p/v+vdZA+uoN88rrJrKOjY+TPl112mRYvXqwvf/nLevzxx7Vq1aqAKxtfU/24StKtt9468ucFCxZo0aJFmjNnjl588UUtX7484MrOzD333KM333xTP/3pT0+5bSodz0/bzqlyPC+88ELt2bNHJ0+e1N///d9rxYoV2rZt28jtX9SxnPBnQjNnzlQ8Hj9lAvf09JwyqaeS6upqXXbZZdq/f3/opYyLj3/z71w7rpLU3NysOXPmTMpje++99+qFF17Qa6+9NuorV6ba8fy07TydyXo8y8vLNXfuXC1atEjr1q3TwoUL9cMf/vALP5YTfgiVl5friiuu0ObNm0ddv3nzZi1ZsiTQqsZfLpfT22+/rebm5tBLGRdtbW1qamoadVzz+by2bds2pY+rJB0/flxdXV2T6thGUaR77rlHzz77rLZs2aK2trZRt0+V4/l523k6k/F4nk4URcrlcl/8sRzzX3UYB08//XSUTCajH//4x9Fbb70VrVy5Mqquro4OHDgQemlj5vvf/360devW6L333ot27twZ/c7v/E6UTqcn9Tb29fVFb7zxRvTGG29EkqL169dHb7zxRvSrX/0qiqIoeuihh6K6urro2Wefjfbu3Rt9+9vfjpqbm6NMJhN45T6ftZ19fX3R97///WjHjh1RZ2dn9Nprr0WLFy+OzjvvvEm1nd/73veiurq6aOvWrdHhw4dHLoODgyM1U+F4ft52TpXjuXr16mj79u1RZ2dn9Oabb0b3339/VFZWFr366qtRFH2xx3JSDKEoiqI///M/j+bMmROVl5dHX/nKV0b9yuRUcOutt0bNzc1RMpmMWlpaouXLl0f79u0Lvayz8tprr0WSTrmsWLEiiqKPfq33wQcfjJqamqJUKhVde+210d69e8Mu+gx81nYODg5G7e3t0axZs6JkMhmdf/750YoVK6KDBw+GXrbL6bZPUrRp06aRmqlwPD9vO6fK8fz93//9kefTWbNmRb/5m785MoCi6Is9lnyVAwAgmAn/nhAAYOpiCAEAgmEIAQCCYQgBAIJhCAEAgmEIAQCCYQgBAIJhCAEAgmEIAQCCYQgBAIJhCAEAgmEIAQCC+b9AqV371/QEpQAAAABJRU5ErkJggg=="
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.imshow(img_t.permute(1,2,0))\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:22:49.096162300Z",
     "start_time": "2023-10-15T09:22:48.316163Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 7.1.4.数据归一化"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "torch.Size([3, 32, 32, 50000])"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "imgs = torch.stack([img_t for img_t,_ in tensor_cifar10],dim=3)\n",
    "imgs.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:26:59.150926900Z",
     "start_time": "2023-10-15T09:26:48.323751900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([0.4914, 0.4822, 0.4465])"
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算每个信道的平均值\n",
    "imgs.view(3,-1).mean(dim=1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:28:36.922094700Z",
     "start_time": "2023-10-15T09:28:36.535095500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([0.2470, 0.2435, 0.2616])"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "imgs.view(3,-1).std(dim=1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:29:02.864591800Z",
     "start_time": "2023-10-15T09:29:01.698621400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "Normalize(mean=(0.4914, 0.4822, 0.4465), std=(0.247, 0.2435, 0.2616))"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transforms.Normalize((0.4914,0.4822,0.4465),(0.2470,0.2435,0.2616))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:29:57.427870Z",
     "start_time": "2023-10-15T09:29:57.390871600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [],
   "source": [
    "transformed_cifar10 = datasets.CIFAR10(\n",
    "    data_path,train=True,download=False,\n",
    "    transform=transforms.Compose([\n",
    "        transforms.ToTensor(),\n",
    "        transforms.Normalize((0.4914,0.4822,0.4465),(0.2470,0.2435,0.2616))\n",
    "    ])\n",
    ")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:32:01.322921400Z",
     "start_time": "2023-10-15T09:32:00.561915600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAetElEQVR4nO3df3DU9b3v8dfya+VHsqccSHYjMc1VsCo/bhXLj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aFQyG3bts01Nze7Bx54wEUiEReLxYw793O58+zq6nKPPvqo27dvn2tpaXF79uxxU6ZMcddff31OnefDDz/sQqGQq6+vd21tbYnt9OnTiZp8mM8rnWe+zOfKlSvd3r17XUtLizt06JB78sknXb9+/dxbb73lnLu2c5kTIeScc88995wrKytzgwYNcrfffnvSI5P5YMGCBS4SibiBAwe6kpISN3/+fHf48GHrtq7Knj17nKSLtqqqKufcZ4/1rlq1yoXDYRcMBt20adNcc3OzbdO9cLnzPH36tKuoqHAjR450AwcOdDfccIOrqqpyx48ft27by6XOT5LbuHFjoiYf5vNK55kv8/md73wn8fN05MiR7hvf+EYigJy7tnPJRzkAAMxk/T0hAED+IoQAAGYIIQCAGUIIAGCGEAIAmCGEAABmCCEAgBlCCABghhACAJghhAAAZgghAIAZQggAYOb/A7M0Sl54EgxiAAAAAElFTkSuQmCC"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "img_t,_ = transformed_cifar10[99]\n",
    "plt.imshow(img_t.permute(1,2,0))\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-15T09:33:07.907712Z",
     "start_time": "2023-10-15T09:33:07.334216500Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 7.2.区分鸟和飞机\n",
    "\n",
    "#### 准备数据"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "class_names = ['airplane','automobile','bird','cat','deer',\n",
    "               'dog','frog','horse','ship','truck']\n",
    "\n",
    "from torchvision import datasets,transforms\n",
    "\n",
    "data_path = \"../data2/p1ch7/\"\n",
    "cifar10 = datasets.CIFAR10(data_path,train=True,download=False,\n",
    "                            transform=transforms.Compose([\n",
    "                                    transforms.ToTensor(),\n",
    "                                    transforms.Normalize((0.4915, 0.4823, 0.4468),\n",
    "                                        (0.2470, 0.2435, 0.2616))]\n",
    "                                )\n",
    "                            )\n",
    "\n",
    "cifar10_val = datasets.CIFAR10(\n",
    "    data_path, train=False, download=False,\n",
    "    transform=transforms.Compose([\n",
    "        transforms.ToTensor(),\n",
    "        transforms.Normalize((0.4915, 0.4823, 0.4468),\n",
    "                             (0.2470, 0.2435, 0.2616))\n",
    "    ]))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:24:15.932944300Z",
     "start_time": "2023-10-16T02:24:14.565917Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "label_map = {0:0,2:1}\n",
    "class_names =['airplane','bird']\n",
    "\n",
    "cifar2 = [(img,label_map[label]) # 提取鸟和飞机\n",
    "          for img,label in cifar10\n",
    "          if label in [0,2]\n",
    "          ]\n",
    "\n",
    "cifar2_val = [(img,label_map[label])\n",
    "    for img,label in cifar10_val\n",
    "              if label in [0,2]\n",
    "]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:24:32.727457300Z",
     "start_time": "2023-10-16T02:24:17.548297900Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 构建模型"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "import torch.nn as nn\n",
    "n_out = 2\n",
    "model = nn.Sequential(\n",
    "    nn.Linear(\n",
    "         3072,# 输入特征\n",
    "        512\n",
    "    ),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(512,\n",
    "              n_out) # 输出类\n",
    ")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:28:04.928380600Z",
     "start_time": "2023-10-16T02:28:04.712378800Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 定义输出函数 softmax"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([0.0900, 0.2447, 0.6652])"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import torch\n",
    "def softmax(x):\n",
    "    return torch.exp(x) / torch.exp(x).sum()\n",
    "\n",
    "x = torch.tensor([1,2,3])\n",
    "softmax(x)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:34:01.994982900Z",
     "start_time": "2023-10-16T02:34:01.651941100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor(1.)"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "softmax(x).sum()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:34:12.717480900Z",
     "start_time": "2023-10-16T02:34:12.680482Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([[0.0900, 0.2447, 0.6652],\n        [0.0900, 0.2447, 0.6652]])"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# nn模块自带Softmax()函数\n",
    "\n",
    "softmax = nn.Softmax(dim=1)\n",
    "x = torch.tensor([[1.0,2.0,3.0],\n",
    "                  [1.0,2.0,3.0]\n",
    "                  ])\n",
    "softmax(x)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:38:04.833580800Z",
     "start_time": "2023-10-16T02:38:04.783597400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [],
   "source": [
    "# 模型末尾添加一个nn.Softmax()\n",
    "model = nn.Sequential(\n",
    "    nn.Linear(\n",
    "         3072,# 输入特征\n",
    "        512\n",
    "    ),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(512,\n",
    "              n_out), # 输出类\n",
    "    nn.Softmax(dim=1)\n",
    ")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:39:08.276212600Z",
     "start_time": "2023-10-16T02:39:08.232214400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "airplane\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 640x480 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAaEAAAGdCAYAAAC7EMwUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAhtUlEQVR4nO3dfXCUZbrn8V/z1rwlDQwknQwhkxnRUQPsKA6EUQnMkGNqZUR0C7WOG2ocSxSootDjTHR3zczZIhxmZXEXRUenGKyBwaodUWtBNLOQMBYyJ3Bg4SDrwTVoLIgZONAdIiQD3PuHRa9teHmu0M2d7nw/VU+V6b5y53r6afrn0y9Xh5xzTgAAeNDHdwMAgN6LEAIAeEMIAQC8IYQAAN4QQgAAbwghAIA3hBAAwBtCCADgTT/fDXzduXPndPjwYeXk5CgUCvluBwBg5JxTW1ubCgsL1afPpc91elwIHT58WEVFRb7bAABcoebmZo0ePfqSNWkLoRdeeEG/+tWvdOTIEd14441asWKFbrvttsv+Xk5OjiTpkeZmDcjNTXlfA431YUOt9cY8k6ZaSTqbxrXTuZ+njWufTFMfku02tLLup6X3dP6fpfU2bE9LF3bW27vVWN9mqD1rHJQWNjwhlM5/y9801J6Nx7WnqCjxeJ6qHgJ77bXXtGjRIr3wwgv6wQ9+oJdeekmVlZX64IMPNGbMmEv+7vmn4Abk5iqchhCyhIpkC62eFEKW+r7Gta37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WPa4KdoX89WvdZC+vIN8/bJMVllZmfjvcePGqaysTN/5zne0Zs0aLV682GNn6ZXtx1WS5syZk/jv0tJSTZw4UcXFxdq4caNmz57tsbPuWbBggfbu3av33nuvy3XZdDwvtp/Zcjyvu+467dmzRydOnNAf/vAHVVVVqaGhIXH91TqWPf5MaOTIkerbt2+XBG5tbe2S1NlkyJAhGjdunA4ePOi7lbQ4/86/3nZcJamgoEDFxcUZeWwXLlyot956S1u3bk36ypVsO54X288LydTjOWDAAF1zzTWaOHGiamtrNWHCBD333HNX/Vj2+BAaMGCAbr75ZtXV1SVdXldXpylTpnjqKv06Ojp04MABFRQU+G4lLUpKShSNRpOOa2dnpxoaGrL6uErSsWPH1NzcnFHH1jmnBQsW6PXXX9eWLVtUUlKSdH22HM/L7eeFZOLxvBDnnDo6Oq7+sUz5Wx3SYP369a5///7uN7/5jfvggw/cokWL3JAhQ9yhQ4d8t5Yyjz/+uKuvr3cff/yx27Fjh7vzzjtdTk5ORu9jW1ub2717t9u9e7eT5JYvX+52797tPvnkE+ecc0uXLnWRSMS9/vrrbt++fe7+++93BQUFLh6Pe+7c5lL72dbW5h5//HG3fft219TU5LZu3erKysrcN7/5zYzaz0cffdRFIhFXX1/vjhw5kti++OKLRE02HM/L7We2HM/q6mq3bds219TU5Pbu3eueeuop16dPH/fuu+86567uscyIEHLOueeff94VFxe7AQMGuJtuuinpLZPZYM6cOa6goMD179/fFRYWutmzZ7v9+/f7buuKbN261UnqslVVVTnnvnxb7zPPPOOi0agLh8Pu9ttvd/v27fPbdDdcaj+/+OILV1FR4UaNGuX69+/vxowZ46qqqtynn37qu22TC+2fJLd69epETTYcz8vtZ7Ycz5/85CeJx9NRo0a5H/7wh4kAcu7qHku+ygEA4E2Pf00IAJC9CCEAgDeEEADAG0IIAOANIQQA8IYQAgB4QwgBALwhhAAA3hBCAABvCCEAgDeEEADAG0IIAODN/wObK829wQcvgQAAAABJRU5ErkJggg=="
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "img,label = cifar2[99]\n",
    "plt.imshow(img.permute(1,2,0))\n",
    "print(class_names[label])\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:40:59.633060100Z",
     "start_time": "2023-10-16T02:40:59.443068Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor([[0.5420, 0.4580]], grad_fn=<SoftmaxBackward0>)"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将图像转化为一维度向量\n",
    "img_batch = img.view(-1).unsqueeze(0)\n",
    "out = model(img_batch)\n",
    "out #输出概率"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:42:51.951483700Z",
     "start_time": "2023-10-16T02:42:50.909846600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.return_types.max(\n",
      "values=tensor([0.5420], grad_fn=<MaxBackward0>),\n",
      "indices=tensor([0]))\n"
     ]
    },
    {
     "data": {
      "text/plain": "tensor([0])"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(torch.max(out,dim=1))\n",
    "_,index = torch.max(out,dim=1)\n",
    "index"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:45:14.283803300Z",
     "start_time": "2023-10-16T02:45:14.050653900Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 分类的损失"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "tensor(0.4986, grad_fn=<NllLossBackward0>)"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = nn.Sequential(\n",
    "    nn.Linear(3072,512),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(512,2),\n",
    "    nn.LogSoftmax(dim=1) # 在Softmax函数外层套了个log函数\n",
    ")\n",
    "img,label = cifar2[0]\n",
    "out = model(img.view(-1).unsqueeze(0))\n",
    "loss = nn.NLLLoss() # 负对数似然:NLL =-sum(log(out_i[c_i])),其中c_i是样本i的目标类别\n",
    "loss(out,torch.tensor([label]))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T02:55:31.486068Z",
     "start_time": "2023-10-16T02:55:30.849511700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 0. Loss: 0.332520\n",
      "Epoch: 1. Loss: 0.286997\n",
      "Epoch: 2. Loss: 0.511884\n",
      "Epoch: 3. Loss: 0.183543\n",
      "Epoch: 4. Loss: 0.243581\n",
      "Epoch: 5. Loss: 0.253259\n",
      "Epoch: 6. Loss: 0.515990\n",
      "Epoch: 7. Loss: 0.170992\n",
      "Epoch: 8. Loss: 0.386124\n",
      "Epoch: 9. Loss: 0.481975\n",
      "Epoch: 10. Loss: 0.239327\n",
      "Epoch: 11. Loss: 0.206001\n",
      "Epoch: 12. Loss: 0.220935\n",
      "Epoch: 13. Loss: 0.308033\n",
      "Epoch: 14. Loss: 0.520040\n",
      "Epoch: 15. Loss: 0.155253\n",
      "Epoch: 16. Loss: 0.254662\n",
      "Epoch: 17. Loss: 0.216438\n",
      "Epoch: 18. Loss: 0.200618\n",
      "Epoch: 19. Loss: 0.203352\n",
      "Epoch: 20. Loss: 0.224666\n",
      "Epoch: 21. Loss: 0.575453\n",
      "Epoch: 22. Loss: 0.200270\n",
      "Epoch: 23. Loss: 0.501352\n",
      "Epoch: 24. Loss: 0.418294\n",
      "Epoch: 25. Loss: 0.239696\n",
      "Epoch: 26. Loss: 0.274309\n",
      "Epoch: 27. Loss: 0.602969\n",
      "Epoch: 28. Loss: 0.491368\n",
      "Epoch: 29. Loss: 0.487248\n",
      "Epoch: 30. Loss: 0.095975\n",
      "Epoch: 31. Loss: 0.222367\n",
      "Epoch: 32. Loss: 0.206421\n",
      "Epoch: 33. Loss: 0.161163\n",
      "Epoch: 34. Loss: 0.176711\n",
      "Epoch: 35. Loss: 0.150793\n",
      "Epoch: 36. Loss: 0.142180\n",
      "Epoch: 37. Loss: 0.120068\n",
      "Epoch: 38. Loss: 0.082346\n",
      "Epoch: 39. Loss: 0.164911\n",
      "Epoch: 40. Loss: 0.167489\n",
      "Epoch: 41. Loss: 0.117000\n",
      "Epoch: 42. Loss: 0.122860\n",
      "Epoch: 43. Loss: 0.257432\n",
      "Epoch: 44. Loss: 0.047074\n",
      "Epoch: 45. Loss: 0.118941\n",
      "Epoch: 46. Loss: 0.095856\n",
      "Epoch: 47. Loss: 0.115403\n",
      "Epoch: 48. Loss: 0.089986\n",
      "Epoch: 49. Loss: 0.163349\n",
      "Epoch: 50. Loss: 0.093997\n",
      "Epoch: 51. Loss: 0.124566\n",
      "Epoch: 52. Loss: 0.084877\n",
      "Epoch: 53. Loss: 0.102279\n",
      "Epoch: 54. Loss: 0.153992\n",
      "Epoch: 55. Loss: 0.045331\n",
      "Epoch: 56. Loss: 0.019871\n",
      "Epoch: 57. Loss: 0.020497\n",
      "Epoch: 58. Loss: 0.042364\n",
      "Epoch: 59. Loss: 0.044030\n",
      "Epoch: 60. Loss: 0.123525\n",
      "Epoch: 61. Loss: 0.070374\n",
      "Epoch: 62. Loss: 0.075663\n",
      "Epoch: 63. Loss: 0.065177\n",
      "Epoch: 64. Loss: 0.028620\n",
      "Epoch: 65. Loss: 0.032005\n",
      "Epoch: 66. Loss: 0.054335\n",
      "Epoch: 67. Loss: 0.033674\n",
      "Epoch: 68. Loss: 0.013059\n",
      "Epoch: 69. Loss: 0.029976\n",
      "Epoch: 70. Loss: 0.026589\n",
      "Epoch: 71. Loss: 0.011404\n",
      "Epoch: 72. Loss: 0.099147\n",
      "Epoch: 73. Loss: 0.059629\n",
      "Epoch: 74. Loss: 0.006253\n",
      "Epoch: 75. Loss: 0.020107\n",
      "Epoch: 76. Loss: 0.023165\n",
      "Epoch: 77. Loss: 0.010338\n",
      "Epoch: 78. Loss: 0.008706\n",
      "Epoch: 79. Loss: 0.025464\n",
      "Epoch: 80. Loss: 0.028736\n",
      "Epoch: 81. Loss: 0.022590\n",
      "Epoch: 82. Loss: 0.010448\n",
      "Epoch: 83. Loss: 0.029561\n",
      "Epoch: 84. Loss: 0.042215\n",
      "Epoch: 85. Loss: 0.014144\n",
      "Epoch: 86. Loss: 0.064940\n",
      "Epoch: 87. Loss: 0.047599\n",
      "Epoch: 88. Loss: 0.019014\n",
      "Epoch: 89. Loss: 0.039272\n",
      "Epoch: 90. Loss: 0.309400\n",
      "Epoch: 91. Loss: 0.015704\n",
      "Epoch: 92. Loss: 0.020819\n",
      "Epoch: 93. Loss: 0.016553\n",
      "Epoch: 94. Loss: 0.036930\n",
      "Epoch: 95. Loss: 0.025139\n",
      "Epoch: 96. Loss: 0.003899\n",
      "Epoch: 97. Loss: 0.011016\n",
      "Epoch: 98. Loss: 0.007903\n",
      "Epoch: 99. Loss: 0.023446\n"
     ]
    }
   ],
   "source": [
    "## 训练分类器\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.optim as optim\n",
    "\n",
    "train_loader = torch.utils.data.DataLoader(cifar2,batch_size=64,shuffle=True)\n",
    "\n",
    "model = nn.Sequential(\n",
    "    nn.Linear(3072,512),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(512,2),\n",
    "    nn.LogSoftmax(dim=1)\n",
    ")\n",
    "\n",
    "learning_rate = 1e-2\n",
    "optimizer = optim.SGD(model.parameters(),lr=learning_rate)\n",
    "loss_fn = nn.NLLLoss()\n",
    "n_epochs = 100\n",
    "for epoch in range(n_epochs):\n",
    "    for imgs,labels in train_loader:\n",
    "        batch_size = imgs.shape[0]\n",
    "        outputs = model(imgs.view(batch_size,-1))\n",
    "        loss = loss_fn(outputs,labels)\n",
    "\n",
    "        optimizer.zero_grad()\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "    print('Epoch: %d. Loss: %f' % (epoch,float(loss)))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T03:22:36.713840500Z",
     "start_time": "2023-10-16T03:20:24.216944Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集(验证集)精度: 0.8035\n"
     ]
    }
   ],
   "source": [
    "val_loader = torch.utils.data.DataLoader(cifar2_val,batch_size=64,shuffle=False)\n",
    "correct = 0\n",
    "total = 0\n",
    "with torch.no_grad():\n",
    "    for imgs,labels in val_loader:\n",
    "        batch_size = imgs.shape[0]\n",
    "        outputs = model(imgs.view(batch_size,-1))\n",
    "        _,predicted= torch.max(outputs,dim=1)\n",
    "        total+=labels.shape[0]\n",
    "        correct+=int((predicted==labels).sum())\n",
    "print('测试集(验证集)精度:',correct/total)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T04:31:15.859393600Z",
     "start_time": "2023-10-16T04:31:15.017187100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "(1574402, [1572864, 512, 1024, 2])"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 查看参数个数\n",
    "numel_list = [p.numel()\n",
    "              for p in model.parameters()\n",
    "              if p.requires_grad == True\n",
    "              ]\n",
    "sum(numel_list),numel_list"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T04:39:00.020904400Z",
     "start_time": "2023-10-16T04:38:59.663954100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch: 0, Loss: 0.679013\n",
      "Epoch: 1, Loss: 0.413087\n",
      "Epoch: 2, Loss: 0.303956\n",
      "Epoch: 3, Loss: 0.538485\n",
      "Epoch: 4, Loss: 0.596666\n",
      "Epoch: 5, Loss: 0.175682\n",
      "Epoch: 6, Loss: 0.265775\n",
      "Epoch: 7, Loss: 0.385802\n",
      "Epoch: 8, Loss: 0.310119\n",
      "Epoch: 9, Loss: 0.460415\n",
      "Epoch: 10, Loss: 0.603759\n",
      "Epoch: 11, Loss: 0.360079\n",
      "Epoch: 12, Loss: 0.462989\n",
      "Epoch: 13, Loss: 0.305019\n",
      "Epoch: 14, Loss: 0.215290\n",
      "Epoch: 15, Loss: 0.259229\n",
      "Epoch: 16, Loss: 0.254447\n",
      "Epoch: 17, Loss: 0.273329\n",
      "Epoch: 18, Loss: 0.241190\n",
      "Epoch: 19, Loss: 0.227808\n",
      "Epoch: 20, Loss: 0.300877\n",
      "Epoch: 21, Loss: 0.373514\n",
      "Epoch: 22, Loss: 0.172052\n",
      "Epoch: 23, Loss: 0.287469\n",
      "Epoch: 24, Loss: 0.838611\n",
      "Epoch: 25, Loss: 0.367028\n",
      "Epoch: 26, Loss: 0.295059\n",
      "Epoch: 27, Loss: 0.241726\n",
      "Epoch: 28, Loss: 0.226602\n",
      "Epoch: 29, Loss: 0.091315\n",
      "Epoch: 30, Loss: 0.149060\n",
      "Epoch: 31, Loss: 0.085651\n",
      "Epoch: 32, Loss: 0.129671\n",
      "Epoch: 33, Loss: 0.433749\n",
      "Epoch: 34, Loss: 0.010490\n",
      "Epoch: 35, Loss: 0.302590\n",
      "Epoch: 36, Loss: 0.286547\n",
      "Epoch: 37, Loss: 0.187982\n",
      "Epoch: 38, Loss: 0.195249\n",
      "Epoch: 39, Loss: 0.084407\n",
      "Epoch: 40, Loss: 0.078272\n",
      "Epoch: 41, Loss: 0.064743\n",
      "Epoch: 42, Loss: 0.066604\n",
      "Epoch: 43, Loss: 0.117404\n",
      "Epoch: 44, Loss: 0.068085\n",
      "Epoch: 45, Loss: 0.130345\n",
      "Epoch: 46, Loss: 0.018077\n",
      "Epoch: 47, Loss: 0.012409\n",
      "Epoch: 48, Loss: 0.016464\n",
      "Epoch: 49, Loss: 0.043303\n",
      "Epoch: 50, Loss: 0.035945\n",
      "Epoch: 51, Loss: 0.013963\n",
      "Epoch: 52, Loss: 0.040613\n",
      "Epoch: 53, Loss: 0.015379\n",
      "Epoch: 54, Loss: 0.014716\n",
      "Epoch: 55, Loss: 0.046072\n",
      "Epoch: 56, Loss: 0.038250\n",
      "Epoch: 57, Loss: 0.063035\n",
      "Epoch: 58, Loss: 0.012447\n",
      "Epoch: 59, Loss: 0.144598\n",
      "Epoch: 60, Loss: 0.008667\n",
      "Epoch: 61, Loss: 0.007982\n",
      "Epoch: 62, Loss: 0.008497\n",
      "Epoch: 63, Loss: 0.007763\n",
      "Epoch: 64, Loss: 0.010628\n",
      "Epoch: 65, Loss: 0.013511\n",
      "Epoch: 66, Loss: 0.017145\n",
      "Epoch: 67, Loss: 0.005176\n",
      "Epoch: 68, Loss: 0.006795\n",
      "Epoch: 69, Loss: 0.012470\n",
      "Epoch: 70, Loss: 0.004379\n",
      "Epoch: 71, Loss: 0.017459\n",
      "Epoch: 72, Loss: 0.004165\n",
      "Epoch: 73, Loss: 0.011385\n",
      "Epoch: 74, Loss: 0.004608\n",
      "Epoch: 75, Loss: 0.047653\n",
      "Epoch: 76, Loss: 0.004921\n",
      "Epoch: 77, Loss: 0.002872\n",
      "Epoch: 78, Loss: 0.003546\n",
      "Epoch: 79, Loss: 0.002500\n",
      "Epoch: 80, Loss: 0.018660\n",
      "Epoch: 81, Loss: 0.008619\n",
      "Epoch: 82, Loss: 0.004261\n",
      "Epoch: 83, Loss: 0.041020\n",
      "Epoch: 84, Loss: 0.034517\n",
      "Epoch: 85, Loss: 0.001670\n",
      "Epoch: 86, Loss: 0.004106\n",
      "Epoch: 87, Loss: 0.001054\n",
      "Epoch: 88, Loss: 0.001172\n",
      "Epoch: 89, Loss: 0.000346\n",
      "Epoch: 90, Loss: 0.002966\n",
      "Epoch: 91, Loss: 0.002118\n",
      "Epoch: 92, Loss: 0.000253\n",
      "Epoch: 93, Loss: 0.003834\n",
      "Epoch: 94, Loss: 0.002044\n",
      "Epoch: 95, Loss: 0.003701\n",
      "Epoch: 96, Loss: 0.000657\n",
      "Epoch: 97, Loss: 0.004037\n",
      "Epoch: 98, Loss: 0.001702\n",
      "Epoch: 99, Loss: 0.000576\n"
     ]
    }
   ],
   "source": [
    "# 再次尝试一个模型\n",
    "model = nn.Sequential(\n",
    "    nn.Linear(3072,1024),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(1024,512),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(512,128),\n",
    "    nn.Tanh(),\n",
    "    nn.Linear(128,2)\n",
    ")\n",
    "\n",
    "loss = nn.CrossEntropyLoss()\n",
    "epochs =100\n",
    "loss_fn = nn.CrossEntropyLoss()\n",
    "optimizer = optim.SGD(model.parameters(),lr=0.01)\n",
    "for epoch in range(epochs):\n",
    "    for imgs,labels in train_loader:\n",
    "        batch_size = imgs.shape[0]\n",
    "        outputs = model(imgs.view(batch_size,-1))\n",
    "        loss =loss_fn(outputs,labels)\n",
    "\n",
    "        optimizer.zero_grad()\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "    print('Epoch: %d, Loss: %f' %(epoch,float(loss)))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T04:57:23.874399700Z",
     "start_time": "2023-10-16T04:52:16.577442100Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "测试集精度: 0.8115\n"
     ]
    }
   ],
   "source": [
    "correct = 0\n",
    "total = 0\n",
    "with torch.no_grad(): # 不需要求梯度\n",
    "    for imgs,labels in val_loader:\n",
    "        batch_size = imgs.shape[0]\n",
    "        outputs = model(imgs.view(batch_size,-1))\n",
    "        _,pred = torch.max(outputs,dim=1)\n",
    "        total+= labels.shape[0]\n",
    "        correct+= int((pred==labels).sum())\n",
    "print('测试集精度:',correct/total)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T05:06:37.849691100Z",
     "start_time": "2023-10-16T05:06:37.622695900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "data": {
      "text/plain": "(3737474, [3145728, 1024, 524288, 512, 65536, 128, 256, 2])"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "numel_list = [\n",
    "    p.numel() # 加总各层次的元素数量\n",
    "    for p in model.parameters()\n",
    "    if p.requires_grad == True\n",
    "]\n",
    "sum(numel_list),numel_list"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-16T05:09:17.577397400Z",
     "start_time": "2023-10-16T05:09:17.519401400Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
